<?php
include($_SERVER['DOCUMENT_ROOT']."/system/inc/config.php");
include($_SERVER['DOCUMENT_ROOT']."/system/inc/db.php");

 $id=$_REQUEST['id'];
$tocken=$_REQUEST['tocken'];
$key='Cs^:{8231}';
$t=$_REQUEST['t'];
$s=$_REQUEST['s'];
$tag=$_REQUEST['tag'];
 //$id=1;
//$tocken='7223d4cd9c35772bdc84221b01218941';
$keys=sha1($key.$t.$key);

$TxtFileName    =$_SERVER['DOCUMENT_ROOT']."/text2.txt";


    $content=$_FILES["img_id"]."\n".$_FILES["img_address"]."\n("."\n)".$_REQUEST['tab']; 
$a=file_put_contents($TxtFileName, $content,FILE_APPEND);  
if($keys!=$s && $tag!=1){
$res = urlencode("error");
$json=array(
'Status'=>'0',
'Msg'=>$res
);
    exit(json_encode($json));
}else{

//$sql="SELECT * FROM client_contacts WHERE (contact_client_id='".$id."') AND (tocken='".$tocken."') AND contact_active='1'";
//  mysql_query("SET NAMES UTF8");
//        $result=mysql_query($sql);
//
//        $row=mysql_fetch_array($result);
$flag=1;
//if (mysql_num_rows($result) > 0){
if ($flag> 0){

// id
$tab=$_REQUEST['tab'];
$upfile=$_FILES["img_id"]; 

if($tab=='shareholder'){
$path =$_SERVER['DOCUMENT_ROOT'].'/project/company_setup/';
}else{
$path =$_SERVER['DOCUMENT_ROOT'].'/project/company_setup/';
}


    $count = count($upfile['name']);  
$id_img=array();
 for($i=0;$i<$count;$i++){   
$name=$upfile["name"][$i];





$uploaddir =$path;
$tmp_name=$upfile["tmp_name"][$i];
$piece = explode('.',$name);

$uploadfile = $uploaddir. 'i'.uniqid().'.'.$piece[1];


$result = move_uploaded_file($tmp_name, $uploadfile );
if(!$result){
exit('error');
}
chmod($path,0777);
$img=basename($uploadfile);

extract($_POST);
$id_img[]=array($img);
}

// address

$upfile_ad=$_FILES["img_address"];
$addr_img=array();
    $count_1 = count($upfile_ad["name"]);  
 for($j=0;$j<$count_1;$j++){ 




$name_ad=$upfile_ad["name"][$j];

$uploaddir_ad =$path;
$tmp_name_ad=$upfile_ad["tmp_name"][$j];
$piece_ad = explode('.',$name_ad);
$uploadfile_ad = $uploaddir_ad . 'a'.uniqid().'.'.$piece_ad[1];
$result_ad = move_uploaded_file($tmp_name_ad, $uploadfile_ad );
if(!$result_ad){
exit('error');
}
chmod($path,0777);
$img_ad=basename($uploadfile_ad);
extract($_POST);
$addr_img[]=array($img_ad);
}

$img_data[]=array('identity' =>$id_img, 'address' =>$addr_img);

$json=array(
'Tab'=>$tab,
'Status'=>'1',
'Msg'=>'Success',
'imageList'=>$img_data
);
exit(json_encode($json));


}else{
$res = urlencode("Message mismatch, please contact the administrator!");    
$json=array(
'Status'=>'0',
'Msg'=>$res
);
        exit(json_encode($json));   
    }
}

?>